PowerSNMP for .NET
ProcessOwnUserKeyChange(SetMessage,Byte[]) Method
Example 




Process a remote keychange request for this user.
Syntax
Public Sub ProcessOwnUserKeyChange( _
   ByVal keyChangeMessage As SetMessage, _
   ByVal engineId() As Byte _
) 
Dim instance As User
Dim keyChangeMessage As SetMessage
Dim engineId() As Byte
 
instance.ProcessOwnUserKeyChange(keyChangeMessage, engineId)
public void ProcessOwnUserKeyChange( 
   SetMessage keyChangeMessage,
   byte[] engineId
)
public: void ProcessOwnUserKeyChange( 
   SetMessage* keyChangeMessage,
   byte[]* engineId
) 
public:
void ProcessOwnUserKeyChange( 
   SetMessage^ keyChangeMessage,
   array<byte>^ engineId
) 

Parameters

keyChangeMessage
engineId

Return Value

Returns the USM User Public value used by the remote party to verify that the keychange was successful
Exceptions
ExceptionDescription
System.ArgumentExceptionThe exception that is thrown when one of the arguments provided to a method is not valid.
System.ExceptionRepresents errors that occur during application execution.
Example
The following example demonstrates how to process a user key change request.
private void SetupRequirements()
{
    //USM User Spinlock variable is required and should be incremented each time it is requested.
    agent1.Variables.Add(agent1.Mib.CreateVariable(NodeName.usmUserSpinLock, "1"));
    //USM USer Public is used to determine if the key change was successful or not. If the 
    agent1.Variables.Add(agent1.Mib.CreateVariable(NodeName.usmUserPublic, "0"));
}

private void requestReceived(Dart.Snmp.Agent agentIn, RequestMessage request, object state)
{
    //Likely keychange request.
    if (request.Variables.Count == 3 && request.Variables[0].GetName() == "1.3.6.1.6.3.15.1.2.1.0 (usmUserSpinLock)" && request is SetMessage)
    {
        //NOTE: Place any additional user or permission verification code here as processing this will change
        //the entity's privacy or authentication key.

        //Make sure our SNMP entity is authoritative for the user.
        if (agentIn.Security.AuthoritativeEngine.Users.ContainsKey(request.Security.User.Name))
        {
            User targetUser = agentIn.Security.AuthoritativeEngine.Users[request.Security.User.Name];

            try
            {
                //Process the change request.
                targetUser.ProcessOwnUserKeyChange(request as SetMessage, request.Security.EngineId);

                //Set the USM User Public variable so that the requesting side can verify that the change request
                //was successful.
                agentIn.Variables[request.Variables[2].Id].Value = request.Variables[2].Value;
            }
            catch(Exception Ex)
            {
                //Keychange failed or setting usm user public failed.
                //Marshal the exception back for handling.
                agent1.Marshal(Ex);
            }
        }
    }
    //Create our response and send it.
    ResponseMessage response = agentIn.CreateResponse(request);
    agentIn.Send(response, request.Origin);
}
Private Sub SetupRequirements()
    'USM User Spinlock variable is required and should be incremented each time it is requested.
    agent1.Variables.Add(agent1.Mib.CreateVariable(NodeName.usmUserSpinLock, "1"))
    'USM USer Public is used to determine if the key change was successful or not.
    agent1.Variables.Add(agent1.Mib.CreateVariable(NodeName.usmUserPublic, "0"))
End Sub

Private Sub requestReceived(ByVal agentIn As Dart.Snmp.Agent, ByVal request As RequestMessage, ByVal state As Object)
    'This is likely a keychange request
    If request.Variables.Count = 3 AndAlso request.Variables(0).GetName() = "1.3.6.1.6.3.15.1.2.1.0 (usmUserSpinLock)" AndAlso TypeOf request Is SetMessage Then

        'NOTE Place anyy additional user Or permission verification code here as processing this will change
        'the entity's privacy or authentication key.

        'Make sure our SNMP entity is authoritative for the user.
        If agentIn.Security.AuthoritativeEngine.Users.ContainsKey(request.Security.User.Name) Then
            Dim targetUser As User = agentIn.Security.AuthoritativeEngine.Users(request.Security.User.Name)

            Try
                'Process the change request.
                targetUser.ProcessOwnUserKeyChange(TryCast(request, SetMessage), request.Security.EngineId)
                'Set the USM User Public variable so that the requesting side can verify that the change request
                'was successful.
                agentIn.Variables(request.Variables(2).Id).Value = request.Variables(2).Value
            Catch Ex As Exception
                'Keychange failed Or setting usm user public failed.
                'Marshal the exception back for handling.
                agent1.Marshal(Ex)
            End Try
        End If
    End If
    'Create our response and send it.
    Dim response As ResponseMessage = agentIn.CreateResponse(request)
    agentIn.Send(response, request.Origin)
End Sub
See Also

Reference

User Class
User Members


PowerSNMP for .NET Documentation Version 8.1
© 2026 Dart Communications. All Rights Reserved.
Send comments on this topic